package kr.hkit.powerjava.chapter13;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

class MainPanel extends JPanel{

	public MainPanel() {
		JButton btn01 = new JButton("버튼1");
		btn01.setBorderPainted(false);		//버튼 테두리 삭제
		btn01.setContentAreaFilled(false);
		btn01.setEnabled(false);			//버튼 비활성화
		JButton btn02 = new JButton("버튼2");
		btn02.setRolloverEnabled(false);
		
		JLabel lbl01 = new JLabel(); //글자 간단히 표시
//		lbl01.setText("Screen Size :("+screenSize.getWidth()+", "+screenSize.getHeight()+")");//화면크기 표시
		
		add(lbl01);
		add(btn01);
		add(btn02);
	
	}
	
}

class TfPanel extends JPanel{

	public TfPanel() {
		JTextField jtf01 = new JTextField(10);
		JTextField jtf02 = new JTextField("텍스트 필드 테스트",10);
		
		add(jtf01);
		add(jtf02);
		
	}
	
}
class MyFrame extends JFrame{
	public MyFrame() throws HeadlessException{
		
		init();
		
	}

	private void init() {
		Toolkit tool = Toolkit.getDefaultToolkit();
		Dimension screenSize = tool.getScreenSize();
		Dimension frameSize = new Dimension(300,200);
		
		int x = (int) (screenSize.getWidth()/2 - frameSize.getWidth()/2);
		int y = (int) (screenSize.getHeight()/2 - frameSize.getHeight()/2);
		
		setLocation(x,y);
		setSize(frameSize);
		
		Image img = tool.getImage("./333.png");	//타이틀 앞 아이콘 설정./=현재 폴더 경로설정도 가능
		setIconImage(img);
		
		/*setLocation((int)screenSize.getWidth()/2-300/2,
				(int)screenSize.getHeight()/2-200/2);
		setSize(300,200);*/
		setTitle("Frame Test2");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		setLayout(new FlowLayout());
		JButton btn01 = new JButton("버튼1");
		btn01.setBorderPainted(false);		//버튼 테두리 삭제
		btn01.setContentAreaFilled(false);
		btn01.setEnabled(false);			//버튼 비활성화
		JButton btn02 = new JButton("버튼2");
		btn02.setRolloverEnabled(false);
		
		JLabel lbl01 = new JLabel(); //글자 간단히 표시
		lbl01.setText("Screen Size :("+screenSize.getWidth()+", "+screenSize.getHeight()+")");//화면크기 표시

		/*add(lbl01);
		add(btn01);
		add(btn02);		*///패널에 추가하겠다
		
/*		JPanel mainPanel = new JPanel(new FlowLayout());
		mainPanel.add(lbl01);
		mainPanel.add(btn01);
		mainPanel.add(btn02);
		mainPanel.setToolTipText("컴포넌트 추가패널");*/
		
		//JPanel tfPanel = new JPanel();
		
		
		add(new MainPanel());
		add(new TfPanel());
		pack();
		//remove(btn02);				//제거
		//setResizable(false);		//창크기 고정
		setVisible(true);
		
	}
	
}
public class FrameTest {
	public static void main(String[] args) {
		
		new MyFrame();
		/* JFrame f = new JFrame("Frame Test");
		//f.setSize(300, 200);
		f.setSize(new Dimension(300, 200));	//사이즈 생략시 사이즈가 없이 나옴
		f.setVisible(true);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		*/
	}
}
